package com.hzlj.position.locate.dao;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.fz.common.base.dto.PageParamDTO;
import com.fz.common.base.dto.QueryPageResultDTO;
import com.hzlj.position.locate.common.dto.abnGathering.AbnGatheringQueryParamDTO;
import com.hzlj.position.locate.common.dto.abnGathering.AbnGatheringQueryResultDTO;
import com.hzlj.position.locate.common.model.AbnGathering;
import com.hzlj.position.locate.common.model.AbnGatheringJzry;
import com.hzlj.position.locate.mapper.AbnGatheringMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * 定位分析-聚众告警表(AbnGathering)表操作类
 *
 * @author lifh
 * @date 2023-03-28 10:20:22
 */
@Repository
public class AbnGatheringDao extends ServiceImpl<AbnGatheringMapper, AbnGathering> {
    @Resource
    private AbnGatheringMapper abnGatheringMapper;

    public void updateTaf(String id, boolean taf) {
        LambdaUpdateWrapper<AbnGathering> updateWrapper = new UpdateWrapper<AbnGathering>().lambda()
                .set(AbnGathering::getTaf, taf)
                .eq(AbnGathering::getId, id);
        this.update(updateWrapper);
    }


    public String getByMinPositionId(String positionId) {
        return QueryWrapperConverterPlus.of(abnGatheringMapper)
                .selectOneField(String.class, q -> {
                    q.select(AbnGathering::getId)
                            .eq(AbnGathering::getMinPositionId, positionId);
                });
    }


    /**
     * 查询列表：分页
     *
     * @param dto  查询条件
     * @param page 分页信息
     * @return 对象列表
     */
    public QueryPageResultDTO<AbnGatheringQueryResultDTO> pageAbnGathering(AbnGatheringQueryParamDTO dto, PageParamDTO page) {
        return QueryWrapperConverterPlus.of(abnGatheringMapper)
                .exists(!ObjectUtil.isAllEmpty(dto.getJgCode(), dto.getXm()),
                        AbnGatheringJzry.class,
                        q -> q.eq(AbnGathering::getId, AbnGatheringJzry::getGatheringId)
                                .likeRight(ObjectUtil.isNotEmpty(dto.getJgCode()), AbnGatheringJzry::getJgCode, dto.getJgCode())
                                .like(ObjectUtil.isNotEmpty(dto.getXm()), AbnGatheringJzry::getXm, dto.getXm()))
                .page(AbnGatheringQueryResultDTO.class, dto, page);
    }


}

